<template>
  <div class="app-container">
    <header-search class="g-w100 g-h100 colon mainSearchPanel">
      <el-form ref="queryForm" :inline="true">
        <el-form-item label="使用单位">
          <el-select filterable clearable placeholder="请选择" v-model="queryParams.sel_sydw">
            <el-option v-for="({ sjxdm, sjxmc }, index) in xlsj1" :key="index" :label="sjxmc" :value="sjxdm"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="使用场所">
          <el-select filterable clearable placeholder="请选择" v-model="queryParams.sel_sycs">
            <el-option v-for="({ sjxdm, sjxmc }, index) in xlsj2" :key="index" :label="sjxmc" :value="sjxdm"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="压力仪表名称">
          <el-select filterable clearable placeholder="请选择" v-model="queryParams.sel_ylybmc">
            <el-option v-for="({ sjxdm, sjxmc }, index) in xlsj3" :key="index" :label="sjxmc" :value="sjxdm"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="保管人">
          <el-select filterable clearable placeholder="请选择" v-model="queryParams.sel_bgr">
            <el-option v-for="({ sjxdm, sjxmc }, index) in xlsj4" :key="index" :label="sjxmc" :value="sjxdm"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="自编号">
          <el-select filterable clearable placeholder="请选择" v-model="queryParams.sel_zbh">
            <el-option v-for="({ sjxdm, sjxmc }, index) in xlsj5" :key="index" :label="sjxmc" :value="sjxdm"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="出厂编号">
          <el-select filterable clearable placeholder="请选择" v-model="queryParams.sel_ccbh">
            <el-option v-for="({ sjxdm, sjxmc }, index) in xlsj6" :key="index" :label="sjxmc" :value="sjxdm"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="ABC分类">
          <el-select filterable clearable placeholder="请选择" v-model="queryParams.sel_abcfl">
            <el-option v-for="({ sjxdm, sjxmc }, index) in xlsj7" :key="index" :label="sjxmc" :value="sjxdm"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="检定性质">
          <el-select filterable clearable placeholder="请选择" v-model="queryParams.sel_jdxz">
            <el-option v-for="({ sjxdm, sjxmc }, index) in xlsj8" :key="index" :label="sjxmc" :value="sjxdm"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="起始日期">
          <el-date-picker v-model="queryParams.sel_qsrq" type="date" format="yyyy-MM-dd" />
        </el-form-item>

        <el-form-item label="截止日期">
          <el-date-picker v-model="queryParams.sel_jzrq" type="date" format="yyyy-MM-dd" />
        </el-form-item>

        <el-form-item class="buttonArea">
          <el-button type="primary" icon="el-icon-search" @click="getListData">查询</el-button>
          <el-button icon="el-icon-refresh" class="commonBtn" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
    </header-search>

    <page-panel-new class="mainListPanel">
      <el-row class="mbBottom">
        <el-col :span="16">
          <el-button type="primary" @click="doAdd('form1')"> 新增 </el-button>
          <el-button type="primary" @click="doExportExcel"> 导出 </el-button>
        </el-col>
      </el-row>
      <el-table ref="table-main" :data="zbdata" height="calc(100% - 113px)" :loading="bgLoading" border >
        <el-table-column label="序号" type="index" width="50" align="center" />
        <el-table-column label="检定标识编号" align="center" prop="jdbsbh" show-overflow-tooltip width="180"  />
        <el-table-column label="使用单位" align="center" prop="sydw" show-overflow-tooltip width="180"  />
        <el-table-column label="使用场所" align="center" prop="sycs" show-overflow-tooltip width="180"  />
        <el-table-column label="保管地点" align="center" prop="bgdd" show-overflow-tooltip width="180"  />
        <el-table-column label="管理标识编号" align="center" prop="glbsbh" show-overflow-tooltip width="180" />
        <el-table-column label="仪器设备名称" align="center" prop="yqsbmc" show-overflow-tooltip width="180" />
        <el-table-column label="规格型号" align="center" prop="ggxh" show-overflow-tooltip width="180" />
        <el-table-column label="自编号" align="center" prop="zbh" show-overflow-tooltip width="180" />
        <el-table-column label="生产厂家" align="center" prop="sccj" show-overflow-tooltip width="180" />
        <el-table-column label="出厂编号" align="center" prop="ccbh" show-overflow-tooltip width="180" />
        <el-table-column label="使用人" align="center" prop="syr" show-overflow-tooltip width="180" />
        <el-table-column label="购置日期" align="center" prop="gzrq" show-overflow-tooltip width="180" />
        <el-table-column label="ABC分类" align="center" prop="abcfl" show-overflow-tooltip width="180" />
        <el-table-column label="质量检测" align="center" prop="zljc" show-overflow-tooltip width="180" />
        <el-table-column label="工艺控制" align="center" prop="gykz" show-overflow-tooltip width="180" />
        <el-table-column label="能源计量" align="center" prop="nyjl" show-overflow-tooltip width="180" />
        <el-table-column label="产能计量" align="center" prop="cnjl" show-overflow-tooltip width="180" />
        <el-table-column label="劳动防护" align="center" prop="ldfh" show-overflow-tooltip width="180" />
        <el-table-column label="强检" align="center" prop="qj" show-overflow-tooltip width="180" />
        <el-table-column label="检定周期(月)" align="center" prop="jdzq" show-overflow-tooltip width="180" />
        <el-table-column label="检定日期" align="center" prop="jdrq" show-overflow-tooltip width="180" />
        <el-table-column label="检定单位" align="center" prop="jddw" show-overflow-tooltip width="180" />
        <el-table-column label="测量介质" align="center" prop="cljz" show-overflow-tooltip width="180" />
        <el-table-column label="测量范围" align="center" prop="clfw" show-overflow-tooltip width="180" />
        <el-table-column label="准确度等级" align="center" prop="zqddj" show-overflow-tooltip width="180" />
        <el-table-column label="准确度" align="center" prop="zqd" show-overflow-tooltip width="180" />
        <el-table-column label="检定性质" align="center" prop="jdxz" show-overflow-tooltip width="180" />
        <el-table-column label="有效期至" align="center" prop="yxqz" show-overflow-tooltip width="180" />
        <el-table-column label="证书编号" align="center" prop="zsbh" show-overflow-tooltip width="180" />
        <el-table-column label="设备状态" align="center" prop="sbzt" show-overflow-tooltip width="180" />
        <el-table-column label="资产属性" align="center" prop="zcsx" show-overflow-tooltip width="180" />
        <el-table-column label="资产编号" align="center" prop="zcbh" show-overflow-tooltip width="180" />
        <el-table-column label="大设备编号" align="center" prop="dsbbh" show-overflow-tooltip width="180" />
        <el-table-column label="备注" align="center" prop="bz" show-overflow-tooltip width="180" />

        <el-table-column label="操作" align="center" class-name="small-padding" width="250" fixed="right">
          <template slot-scope="scope">
            <el-button type="text" class="delbutton" @click="doUpdate(scope.row, scope.$index)"> 修改 </el-button>
            <el-button type="text" class="delbutton" @click="doUpdate1(scope.row, scope.$index)"> 更新检定信息 </el-button>
            <el-button type="text" class="delbutton" @click="doDelete(scope.row, scope.$index)"> 删除 </el-button>
            <el-button type="text" @click="doView(scope.row, scope.$index)"> 查看 </el-button>
          </template>
        </el-table-column>
      </el-table>

      <qjfy :total='total' @fun="qjfyfun"></qjfy>
    </page-panel-new>
    <el-dialog :title="dialogTitle" :visible.sync="Open1" class="qjztk" append-to-body>
      <div class="el-dialog-div">
        <el-form ref="form1" :model="formData" :validate-on-rule-change=false label-width="150px"
          :disabled="formDisable">
          <!-- 基本信息 -->
          <el-form-item label="使用单位">
            <el-select v-model="formData.sydw" prop="sydw" :rules="[
              { required: true, message: '请输入', trigger: 'blur' },
            ]" filterable allow-create default-first-option placeholder="请选择">
              <el-option v-for="({ sjxdm, sjxmc }, index) in xlsj10" :key="index" :label="sjxmc" :value="sjxdm"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="使用场所">
            <el-select v-model="formData.sycs" prop="sycs" :rules="[
              { required: true, message: '请输入', trigger: 'blur' },
            ]" filterable allow-create default-first-option placeholder="请选择">
              <el-option v-for="({ sjxdm, sjxmc }, index) in xlsj11" :key="index" :label="sjxmc" :value="sjxdm"></el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="保管地点">
            <el-select v-model="formData.bgdd" prop="bgdd" :rules="[
              { required: true, message: '请输入', trigger: 'blur' },
            ]" filterable allow-create default-first-option placeholder="请选择">
              <el-option v-for="({ sjxdm, sjxmc }) in xlsj13" :key="sjxdm" :label="sjxmc" :value="sjxdm"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="测量介质">
            <el-select v-model="formData.cljz" prop="bgdd"  filterable allow-create default-first-option placeholder="请选择">
              <el-option v-for="({ sjxdm, sjxmc }, index) in xlsj14" :key="index" :label="sjxmc" :value="sjxdm"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="管理标识编号">
            <el-input v-model="formData.glbsbh" />
          </el-form-item>
          <el-form-item label="检定标识编号">
            <el-input v-model="formData.jdbsbh" />
          </el-form-item>


          <el-form-item label="压力仪表名称">
            <el-input v-model="formData.ylybmc" />
          </el-form-item>

          <el-form-item label="规格型号">
            <el-input v-model="formData.ggxh" />
          </el-form-item>
          <el-form-item label="生产厂家">
            <el-input v-model="formData.sccj" />
          </el-form-item>

          <el-form-item label="自编号">
            <el-input v-model="formData.zbh" prop="zbh" :rules="[
              { required: true, message: '请输入', trigger: 'blur' },
            ]" />
          </el-form-item>
          <el-form-item label="准确度等级">
            <el-select v-model="formData.zqddj" filterable allow-create default-first-option placeholder="请选择">
              <el-option v-for="({ sjxdm, sjxmc }, index) in xlsj15" :key="index" :label="sjxmc" :value="sjxdm"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="测量范围">
          </el-form-item>
          <el-form-item label="准确度">
            <el-input v-model="formData.zqd" type="textarea" :rows="4" />
          </el-form-item>
          <el-form-item label="质量检测">
            <el-input v-model="formData.zljc" type="textarea" :rows="4" />
          </el-form-item>
          <el-form-item label="工艺控制">
            <el-input v-model="formData.gykz" type="textarea" :rows="4" />
          </el-form-item>
          <el-form-item label="能源计量">
            <el-input v-model="formData.nyjl" type="textarea" :rows="4" />
          </el-form-item>
          <el-form-item label="产能计量">
            <el-input v-model="formData.cnjl" type="textarea" :rows="4" />
          </el-form-item>
          <el-form-item label="劳动防护">
            <el-input v-model="formData.ldfh" type="textarea" :rows="4" />
          </el-form-item>
          <el-form-item label="强检">
            <el-input v-model="formData.qj" type="textarea" :rows="4" />
          </el-form-item>
          <el-form-item label="ABC分类">
            <el-select v-model="formData.abcfl" filterable allow-create default-first-option placeholder="请选择">
              <el-option v-for="({ sjxdm, sjxmc }, index) in xlsj16" :key="index" :label="sjxmc" :value="sjxdm"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="保管人">
            <el-select v-model="formData.bgr" filterable allow-create default-first-option placeholder="请选择">
              <el-option v-for="({ sjxdm, sjxmc }, index) in xlsj12" :key="index" :label="sjxmc" :value="sjxdm"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="购置日期">
            <el-date-picker v-model="formData.gzrq" type="date" format="yyyy-MM-dd" value-format="yyyy-MM-dd">
            </el-date-picker>
          </el-form-item>
           <el-form-item label="出厂编号">
            <el-input v-model="formData.ccbh" />

          </el-form-item>
          <el-form-item label="设备状态">
            <el-select v-model="formData.sbzt" filterable allow-create default-first-option placeholder="请选择">
              <el-option v-for="({ sjxdm, sjxmc }, index) in xlsj1" :key="index" :label="sjxmc" :value="sjxdm"></el-option>
            </el-select>
          </el-form-item>
          

          <el-form-item label="备注">
            <el-input v-model="formData.bz" type="textarea" :rows="4" />
          </el-form-item>
        </el-form>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button v-if="!formDisable" type="primary" @click="doSubmit"> 保存 </el-button>
        <el-button class="cancelBtn" @click="doClose"> 关 闭 </el-button>
      </div>
    </el-dialog>
    <!-- xxxxxx -->
    <el-dialog title="更新检定信息" :visible.sync="Open2"  class="qjdtk" append-to-body>
      <gxjdxx :popobj="formData"></gxjdxx>
    </el-dialog>
  </div>
</template>
<script lang="ts">
import Vue from 'vue'
// xxxxxx
import gxjdxx from './gxjdxx.vue'
import dayjs from 'dayjs'



export default Vue.extend({
   name: 'Sbgl-sbjdjz-jlqjjd',
  data() {
    return {
      title: '计量器具检定', //页面标题
      jklj: 'yqsbgl/sbjdjz/jlqjjd', // 接口路径
      dialogTitle: '', // 弹框标题
      bgLoading: false, // 表格加载状态
      Open1: false, //弹框状态
      Open2: false, //弹框状态xxxxxx
      // 查看详细信息,查看检定证书,使用单位,使用场所,保管地点,管理标识编号,检定标识编号,仪器设备名称,规格型号,自编号,生产厂家,
      // 出厂编号,使用人,购置日期,ABC分类,质量检测,工艺控制, 能源计量,产能计量,劳动防护,强检,
      // 工艺控制,能源计量,产能计量,劳动防护,强检,检定周期(月,检定日期,检定单位,测量介质,测量范围,准确度等级,准确度,检定性质,
      // 有效期至,证书编号,设备状态,资产属性,资产编号,大设备编号,备注
      zbdata: [
        
      ], //主表格数据
      xlsj1: [],//查询选择器 下拉数据
      xlsj2: [],//查询选择器 下拉数据
      xlsj3: [],//查询选择器 下拉数据
      xlsj4: [],//查询选择器 下拉数据
      xlsj5: [],//查询选择器 下拉数据
      xlsj6: [],//查询选择器 下拉数据
      xlsj7: [],//查询选择器 下拉数据
      xlsj8: [],//查询选择器 下拉数据
      xlsj9: [],//查询选择器 下拉数据
      xlsj10: [],//查询选择器 下拉数据
      xlsj11: [],//查询选择器 下拉数据
      xlsj12: [],//查询选择器 下拉数据
      xlsj13: [],//查询选择器 下拉数据
      xlsj14: [],//查询选择器 下拉数据
      xlsj15: [],//查询选择器 下拉数据
      xlsj16: [],//查询选择器 下拉数据
      xlsj17: [],//查询选择器 下拉数据
      xlsj18: [],//查询选择器 下拉数据
      xlsj19: [],//查询选择器 下拉数据


      optype: 'xz', //操作类型
      fjid: '', //附件ID
      keycz: 0, //附件上传key
      fileList: [],
      fileList_fj: [],
      formData: {
        "jdbsbh": "", //检定标识编号
        "sydw": "", //使用单位
        "sycs": "", //使用场所
        "bgdd": "", //保管地点
        "glbsbh": "", //管理标识编号
        "yqsbmc": "", //仪器设备名称
        "ggxh": "", //规格型号
        "zbh": "", //自编号
        "sccj": "", //生产厂家
        "ccbh": "", //出厂编号
        "syr": "", //使用人
        "gzrq": "", //购置日期
        "abcfl": "", //ABC分类
        "zljc": "", //质量检测
        "gykz": "", //工艺控制
        "nyjl": "", //能源计量
        "cnjl": "", //产能计量
        "ldfh": "", //劳动防护
        "qj": "", //强检
        "jdzq": "", //检定周期(月)
        "jdrq": "", //检定日期
        "jddw": "", //检定单位
        "cljz": "", //测量介质
        "clfw": "", //测量范围
        "zqddj": "", //准确度等级
        "zqd": "", //准确度
        "jdxz": "", //检定性质
        "yxqz": "", //有效期至
        "zsbh": "", //证书编号
        "sbzt": "", //设备状态
        "zcsx": "", //资产属性
        "zcbh": "", //资产编号
        "dsbbh": "", //大设备编号
        "bz": "", //备注

        // 以下为无对应中文注释字段（保持原始顺序）
        "s_zhxgr": "",
        "id": "",
        "s_cjr": "",
        "fileid": "",
        "s_cjsj": "",
        "xh": "",
        "s_zhxgsj": ""
      }

      , //录入Form数据
      formDisable: false, //表单禁用状态
      queryParams: {
        sel_sydw: '',       // 使用单位 (previously sel_dw)
        sel_sycs: '',       // 使用场所 (previously sel_cs)
        sel_ylybmc: '',     // 客户设备名称 (previously sel_yqsbmc)
        sel_bgr: '',        // 报告人 (previously sel_syr)
        sel_zbh: '',        // 自编号 (unchanged)
        sel_ccbh: '',       // 出厂编号 (unchanged)
        sel_abcfl: '',      // ABC分类 (previously sel_abc)
        sel_jdxz: '',       // 检定性质 (unchanged)
        sel_qsrq: null,     // 起始日期 (new parameter)
        sel_jzrq: null,     // 截止日期 (new parameter, replacing sel_jdrq)
        start: 1,           // 分页起始位置 (unchanged)
        limit: 20,          // 每页显示条数 (unchanged)
      },
      total: 0,

    }
  },
  computed: {
  },
  // xxxxxx
  components: {
    gxjdxx,
  },
  watch: {
    optype: {
      handler(newVal, oldVal) {
        if (newVal == 'ck') {
          this.formDisable = true;
        } else {
          this.formDisable = false;
        }
      },
      deep: true,
    },
    queryParams: {
      handler(newVal, oldVal) {
        this.getxlsj1();
      },
      deep: true,
    },
  },
  mounted() {
    this.getListData();
    this.getxlsj1();
  },
  methods: {
    //获取 选择器数据
    getxlsj1() {
      try {
        const param = {};
        // sel_dw: '',       // 使用单位
        // sel_cs: '',       // 使用场所
        // sel_yqsbmc: '',   // 仪器设备名称
        // sel_syr: '',      // 使用人
        // sel_zbh: '',      // 自编号
        // sel_ccbh: '',     // 出厂编号
        // sel_abc: '',      // ABC分类
        // sel_jdxz: '',     // 检定性质
        // sel_jdrq: null,   // 计划送检日期
        // start: 1,         // 分页起始位置
        // limit: 20,        // 每页显示条数
        this.$getSelectorData("sydw", param, this.jklj).then((res) => {  // 仪器设备名称（yq对应yqsbmc）
          this.xlsj1 = res.success ? res.rows : [];
        })
        this.$getSelectorData("sycs", param, this.jklj).then((res) => {  // 仪器设备名称（yq对应yqsbmc）
          this.xlsj2 = res.success ? res.rows : [];
        })
        this.$getSelectorData("ylybmc", param, this.jklj).then((res) => {  // 仪器设备名称（yq对应yqsbmc）
          this.xlsj3 = res.success ? res.rows : [];
        })

        this.$getSelectorData("bgr", param, this.jklj).then((res) => {  // 使用人
          this.xlsj4 = res.success ? res.rows : [];
        })

        this.$getSelectorData("zbh", param, this.jklj).then((res) => {  // 自编号
          this.xlsj5 = res.success ? res.rows : [];
        })

        this.$getSelectorData("ccbh", param, this.jklj).then((res) => {  // 出厂编号
          this.xlsj6 = res.success ? res.rows : [];
        })

        this.$getSelectorData("abcfl", param, this.jklj).then((res) => {  // ABC分类
          this.xlsj7 = res.success ? res.rows : [];
        })

        this.$getSelectorData("jdxz", param, this.jklj).then((res) => {  // 检定性质
          this.xlsj8 = res.success ? res.rows : [];
        })
        this.$getSelectorData("in_ejdw", param, this.jklj).then((res) => {  
          this.xlsj9 = res.success ? res.rows : [];
        })
        this.$getSelectorData("in_sydw", param, this.jklj).then((res) => {  
          this.xlsj10 = res.success ? res.rows : [];
        })
        this.$getSelectorData("in_sycs", param, this.jklj).then((res) => {  
          this.xlsj11 = res.success ? res.rows : [];
        })
        this.$getSelectorData("in_bgr", param, this.jklj).then((res) => {  
          this.xlsj12 = res.success ? res.rows : [];
        })
        this.$getSelectorData("in_bgdd", param, this.jklj).then((res) => {  
          this.xlsj13 = res.success ? res.rows : [];
        })
        this.$getSelectorData("in_cljz", param, this.jklj).then((res) => {  
          this.xlsj14 = res.success ? res.rows : [];
        })
        this.$getSelectorData("in_zqddj", param, this.jklj).then((res) => {  
          this.xlsj15 = res.success ? res.rows : [];
        })
        this.$getSelectorData("in_abcfl", param, this.jklj).then((res) => {  
          this.xlsj16 = res.success ? res.rows : [];
        })
        this.$getSelectorData("in_jddw", param, this.jklj).then((res) => {  
          this.xlsj17 = res.success ? res.rows : [];
        })
        this.$getSelectorData("in_jdxz", param, this.jklj).then((res) => {  
          this.xlsj18 = res.success ? res.rows : [];
        })

      } catch (error) {
        console.warn('接口提示', error)
      }
    },
    //查询参数重置按钮事件
    resetQuery() {
      this.queryParams = {
        sel_dw: '',       // 使用单位
        sel_cs: '',       // 使用场所
        sel_yqsbmc: '',   // 仪器设备名称
        sel_syr: '',      // 使用人
        sel_zbh: '',      // 自编号
        sel_ccbh: '',     // 出厂编号
        sel_abc: '',      // ABC分类
        sel_jdxz: '',     // 检定性质
        sel_jdrq: null,   // 计划送检日期
        start: 1,         // 分页起始位置
        limit: 20,        // 每页显示条数
      };
      this.getListData()
    },
    czcxfun() {
      this.keycz++
      this.formData = {
        "jdbsbh": "", //检定标识编号
        "sydw": "", //使用单位
        "sycs": "", //使用场所
        "bgdd": "", //保管地点
        "glbsbh": "", //管理标识编号
        "yqsbmc": "", //仪器设备名称
        "ggxh": "", //规格型号
        "zbh": "", //自编号
        "sccj": "", //生产厂家
        "ccbh": "", //出厂编号
        "syr": "", //使用人
        "gzrq": "", //购置日期
        "abcfl": "", //ABC分类
        "zljc": "", //质量检测
        "gykz": "", //工艺控制
        "nyjl": "", //能源计量
        "cnjl": "", //产能计量
        "ldfh": "", //劳动防护
        "qj": "", //强检
        "jdzq": "", //检定周期(月)
        "jdrq": "", //检定日期
        "jddw": "", //检定单位
        "cljz": "", //测量介质
        "clfw": "", //测量范围
        "zqddj": "", //准确度等级
        "zqd": "", //准确度
        "jdxz": "", //检定性质
        "yxqz": "", //有效期至
        "zsbh": "", //证书编号
        "sbzt": "", //设备状态
        "zcsx": "", //资产属性
        "zcbh": "", //资产编号
        "dsbbh": "", //大设备编号
        "bz": "", //备注

        // 以下为无对应中文注释字段（保持原始顺序）
        "s_zhxgr": "",
        "id": "",
        "s_cjr": "",
        "fileid": "",
        "s_cjsj": "",
        "xh": "",
        "s_zhxgsj": ""
      }
    },
    qjfyfun(e) {//分页
      this.queryParams.start = e.start;
      this.queryParams.limit = e.limit;
    },
    sjfwfun(e, e1) {//日期范围选择器事件
      this.queryParams.sel_qsrq = e;
      this.queryParams.sel_jzrq = e1;
    },
    handleUploadChange_d(file, filelist) { //上传文件改变事件
      var _fileData = new FormData();
      _fileData.append("bizPath", "syfxxt/khfw");
      _fileData.append("uploadType", "minio");
      _fileData.append("file", file.raw, file.name);
      this.$uploadFile(_fileData).then((res) => {
        if (res.data.code === 200) {
          file.minioID = res.data.data.split(":")[0];
          file.filename = file.name;
          this.dgfjwj.uploadFiles = filelist;
        } else {
          this.$message.error({ content: '上传失败!', placement: 'center' })
          filelist.splice(filelist.indexOf(file), 1);
          this.dgfjwj.uploadFiles = filelist;
        }
      })
        .catch(() => {
          this.$message.error({ content: '上传失败!', placement: 'center' });
          filelist.splice(filelist.indexOf(file), 1);
          this.dgfjwj.uploadFiles = filelist;
        });
    },
    handleUploadChange_h(file, filelist) {
      var _fileData = new FormData();
      _fileData.append("bizPath", "syfxxt/khfw");
      _fileData.append("uploadType", "minio");
      _fileData.append("file", file.raw, file.name);
      this.$uploadFile(_fileData).then((res) => {
        if (res.data.code === 200) {
          file.minioID = res.data.data.split(":")[0];
          file.filename = file.name;
          this.hdfjwj.uploadFiles = filelist;
        } else {
          this.$message.error({ content: '上传失败!', placement: 'center' })
          filelist.splice(filelist.indexOf(file), 1);
          this.hdfjwj.uploadFiles = filelist;
        }
      })
        .catch(() => {
          this.$message.error({ content: '上传失败!', placement: 'center' });
          filelist.splice(filelist.indexOf(file), 1);
          this.hdfjwj.uploadFiles = filelist;
        });
    },
    handleUploadBeforeRemove_d(file) {//上传文件删除前事件
      if (file.fileid && file.fjid) {
        return this.$modal.confirm("该文件已上传，确认删除该文件？");
      } else {
        return true;
      }
    },
    handleUploadBeforeRemove_h(file, filelist) {
      if (file.fileid && file.fjid) {
        return this.$modal.confirm("该文件已上传，确认删除该文件？");
      } else {
        return true;
      }
    },
    handleUploadRemove_d(file, filelist) {//上传文件删除事件
      this.dgfjwj.uploadFiles = filelist;
      if (file.fileid && file.id) {
        this.$submit_delfile({ fileid: file.fileid, id: file.id }, this.jklj)
          .then((res) => {
            if (res.success) {
              this.$message.success({ content: '删除成功!', placement: 'center' })
            } else {
              this.$message.error({ content: '删除失败!', placement: 'center' })
            }
          })
          .catch(() => {
            this.$message.error({ content: '删除失败!', placement: 'center' })
          });
      }
    },
    handleUploadRemove_h(file, filelist) {
      this.hdfjwj.uploadFiles = filelist;
      if (file.fileid && file.fjid) {
        this.$submit_delfile_fj({ fileid: file.fileid, fjid: file.fjid, tzggid: this.formData.id }, this.jklj)
          .then((res) => {
            if (res.success) {
              this.$message.success({ content: '删除成功!', placement: 'center' })
            } else {
              this.$message.error({ content: '删除失败!', placement: 'center' })
            }
          })
          .catch(() => {
            this.$message.error({ content: '删除失败!', placement: 'center' })
          });
      }
    },
    getListData() { //获取主表格查询数据
      try {
        this.bgLoading = true
        this.$getListData(this.queryParams, this.jklj).then((res) => {
          if (res.success) {
            this.zbdata = res.rows;
            this.total = res.total;
          } else {
            this.zbdata = []
            this.$message.error({ content: '请重新搜索!', placement: 'center' })
          }
        })
      } catch (error) {
        this.bgLoading = false;
        console.warn('接口提示', error);
      }
    },
    doSubmit() {//处理保存按钮事件
      this.$refs['form1'].validate((valid) => {
        if (valid) {
          var _data = { ...this.formData };
          var _submitData = new FormData();
          for (let key in _data) {
            if (_data[key] && _data[key] instanceof Date) {
              _data[key] = dayjs(_data[key]).format('YYYY-MM-DD');
            }
            _submitData.append(key, _data[key]);
          }
           var _fileList_fj = [];
          var _fileList = [];
          if (this.hdfjwj && this.hdfjwj.uploadFiles) {
            this.hdfjwj.uploadFiles.forEach(file => {
              if (file.status == 'ready' && file.minioID) {
                _fileList_fj.push(file);
              }
            });
          }
          if (this.dgfjwj && this.dgfjwj.uploadFiles) {
            this.dgfjwj.uploadFiles.forEach(file => {
              if (file.status == 'ready' && file.minioID) {
                _fileList.push(file);
              }
            });
          }
          
          this.$submit(_submitData, this.jklj)
            .then((res) => {
              if (res.success) {
                this.$message.success({ content: '保存成功!', placement: 'center' })
                this.Open1 = false;
                this.getListData()
                this.getxlsj1()
              } else {
                this.$message.error({ content: '保存失败!', placement: 'center' })
              }
            })
            .catch(() => {
              this.$message.error({ content: '保存失败!', placement: 'center' })
            });
        }
      });
    },
    doSubmit1() {//处理保存按钮事件
      this.$refs['form1'].validate((valid) => {
        if (valid) {
          var _data = { ...this.formData };
          var _submitData = new FormData();
          for (let key in _data) {
            if (_data[key] && _data[key] instanceof Date) {
              _data[key] = dayjs(_data[key]).format('YYYY-MM-DD');
            }
            _submitData.append(key, _data[key]);
          }
           var _fileList_fj = [];
          var _fileList = [];
          if (this.hdfjwj && this.hdfjwj.uploadFiles) {
            this.hdfjwj.uploadFiles.forEach(file => {
              if (file.status == 'ready' && file.minioID) {
                _fileList_fj.push(file);
              }
            });
          }
          if (this.dgfjwj && this.dgfjwj.uploadFiles) {
            this.dgfjwj.uploadFiles.forEach(file => {
              if (file.status == 'ready' && file.minioID) {
                _fileList.push(file);
              }
            });
          }
          _submitData.append("fileList", JSON.stringify(_fileList));
          
          this.$submit_qt(_submitData, this.jklj,'jdxx')
            .then((res) => {
              if (res.success) {
                this.$message.success({ content: '保存成功!', placement: 'center' })
                this.Open1 = false;
                this.getListData()
                this.getxlsj1()
              } else {
                this.$message.error({ content: '保存失败!', placement: 'center' })
              }
            })
            .catch(() => {
              this.$message.error({ content: '保存失败!', placement: 'center' })
            });
        }
      });
    },
    doAdd(formName) {//处理新增按钮事件
      this.Open1 = true;
      this.optype = 'xz';
      this.czcxfun();
      this.formData.optype = 'add';
      this.dialogTitle = this.title + ' >> 新增';
    },
    doUpdate(row) {//处理修改按钮事件
      this.czcxfun();
      this.xzsj = row;
      this.Open1 = true;
      this.optype = 'xg';
      this.dialogTitle = this.title + ' >> 修改';
      this.formData = { ...row };
      this.formData.optype = 'update';
      // 附件查看
      const param = {
        start: 0,
        limit: 100,
        sel_tzggid: this.formData.id,
      };
      this.$getListData_fj(param, this.jklj).then((res) => {
        if (res.success) {
          this.hdfjwj.uploadFiles = res.rows;
          this.hdfjwj.uploadFiles.forEach(file => {
            file.name = file.filename;
            file.status = 'success';
          });
        } else {
          this.hdfjwj.uploadFiles = []
          this.$message.error({ content: '请重新搜索!', placement: 'center' })
        }
      })
      
    },
    // xxxxxx
    doUpdate1(row) {//处理修改按钮事件
      this.czcxfun();
      this.xzsj = row;
      this.Open2 = true;
      this.optype = 'xg';
      this.formData = { ...row };
      this.formData.optype = 'update';
    },
    doDelete(row) {//处理删除按钮事件
      return this.$modal.confirm("是否确认删除该条数据？")
        .then(() => {
          this.$submit_delete({ id: row.id }, this.jklj)
            .then((res) => {
              if (res.success) {
                this.getListData()
                this.$message.success({ content: '删除成功!', placement: 'center' })
              } else {
                this.$message.error({ content: '删除失败!', placement: 'center' })
              }
            })
            .catch(() => {
              this.$message.error({ content: '删除失败!', placement: 'center' })
            });
        })
        .catch(() => {
        });
    },
    //处理导出按钮事件
    doExportExcel() {
      var params = { ...this.queryParams };
      for (let key in params) {
        if (/^sel_/.test(key)) {
          var new_key = key.replace(/^sel_/, 'p_');
          params[new_key] = params[key];
        }
      }
      try {
        if (!this.queryParams) {
          this.$message.info({ content: '请先查询数据!', placement: 'center' })
        }
        const filename = this.title + '-' + dayjs().format('YYYYMMDDHHmmssSSS') + '.xls';
        this.$exportExcel(this.download, params, filename, this.jklj);
      } catch (error) {
      }
    },
    doView(row) {//处理查看按钮事件
      this.Open1 = true;
      this.optype = 'ck';
      this.dialogTitle = this.title + ' >> 查看';
      this.formData = { ...row };
    },
    doViewFJ(row) {//处理查看附件按钮事件
      this.$refs.ckfj.dkfj({ start: 0, limit: 100, sel_tzggid: row.id, }, this.jklj);
    },
    doClose() {//处理关闭事件
      this.Open1 = false;
      this.Open2 = false;
    },
  },
})
</script>
<style lang="less" scoped>
.app-container {
  height: 100%;

  .el-table {
    overflow: scroll;
  }
}

::v-deep .el-dialog__body {
  max-height: 60vh;
  overflow-y: auto;
}

.delbutton {
  margin-right: 10px;
}

.mbBottom {
  margin-bottom: 10px;
}

.mainSearchPanel .page-header-title {
  font-size: 16px;
  color: #409EFF;
  font-weight: bolder;
  display: block;
  margin: 10px 0;
}
</style>
